
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import java.util.Random;
import java.util.HashMap;
public class Test {
    //10W数组去重
    public static void fun1(int[] array){
        Set<Integer> set = new HashSet<>();
        for(int i = 0; i < array.length; i++){
            set.add(array[i]);
        }
        System.out.print(set);
    }
    //找出10w个数据中第一个重复的数据
    public static void fun2(int[] array){
        Set<Integer> set = new HashSet<>();
        int key = 0;
        for(int i = 0; i < array.length; i++){
            if(set.contains(array[i])){
                key = array[i];
                break;
            }
            set.add(array[i]);
        }
        System.out.println(key);
    }
    //统计10W个数据中每个数据出现的次数
    public static void fun3(int[] array){
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < array.length; i++){
            if(map.get(array[i]) == null){
                map.put(array[i],1);
            }else{
                map.put(array[i], map.get(array[i])+1);
            }
        }
        System.out.println(map);
    }
    public static void main(String[] args){
        Random random = new Random();
        int[] array = new int[10_0000];
        for(int i = 0; i < array.length; i++){
            array[i] = random.nextInt(5001);
        }
        int[] arrayTmp = {1,2,2,5,5,7,9,4,4,5};
        fun3(arrayTmp);
    }
}
